package com.bkgy.modular.tpdidata_cal1630.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.tpdidata_cal1630.entity.TPdiData1630Request;
import com.bkgy.modular.tpdidata_cal1630.entity.TPdiDataCal1630;
import com.bkgy.modular.tpdidata_cal1630.entity.TPdiDataCal1630Resp;
import com.bkgy.modular.tpdidata_cal1630.mapper.TPdiDataCal1630Mapper;
import com.bkgy.modular.tpdidata_cal1630.service.TPdiDataCal1630Service;
import com.bkgy.modular.tpdodata_cal1630.entity.TPdoData1630Request;
import com.bkgy.modular.tpdodata_cal1630.entity.TPdoDataCalBao1630;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author dell
* @description 针对表【T_PDI_DATA_CAL1630(2150连退生产计划表)】的数据库操作Service实现
* @createDate 2025-04-08 15:27:02
*/
@Service
public class TPdiDataCal1630ServiceImpl extends ServiceImpl<TPdiDataCal1630Mapper, TPdiDataCal1630>
    implements TPdiDataCal1630Service{

    @Autowired
    private TPdiDataCal1630Mapper tPdiDataCal1630Mapper;


    /**
     * 分页查看记录
     * @param data 分页参数字符串
     */
    public ResultData findDataByPage(String data) {
        try {
            TPdiData1630Request tPdiData1630Request = JSON.parseObject(data, TPdiData1630Request.class);
            JSONObject jsonObject  = null;
            Integer pageIndex = tPdiData1630Request.getPageIndex();
            Integer pageSize = tPdiData1630Request.getPageSize();

            if(null == pageIndex || null == pageSize){
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }

            if(null!=tPdiData1630Request.getCondition()){
                jsonObject  = JSON.parseObject(tPdiData1630Request.getCondition().toString());
            }
//
//            QueryWrapper<TPdiDataCal1630> queryWrapper = new QueryWrapper<TPdiDataCal1630>();
//            queryWrapper.orderByDesc("CREATE_TIME");

            Page<TPdiDataCal1630Resp> page = new Page<TPdiDataCal1630Resp>(pageIndex, pageSize);
            IPage<TPdiDataCal1630Resp> list = tPdiDataCal1630Mapper.findDataByPage(page, jsonObject);

            return ResultData.ResultDataSuccess(list,(int)list.getTotal());
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }



    public ResultData findSteelGradeByInDocNo(String data){
        try {
            TPdiDataCal1630 tPdiDataCal1630 = JSON.parseObject(data, TPdiDataCal1630.class);
            List<TPdiDataCal1630Resp> list = tPdiDataCal1630Mapper.findSteelGradeByInDocNo(tPdiDataCal1630);

            return ResultData.ResultDataSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }


    }

}




